home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 October: Mac OS SDK / Dev.CD Oct 00 SDK1.toast / Development Kits / Mac OS / Appearance SDK 1.0.4 / Appearance Sample Code / Source / AppearanceHelpers.c next >
Encoding:
C/C++ Source or Header  |  1999-07-16  |  24.0 KB  |  873 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        AppearanceHelpers.c
  3.  
  4.     Contains:    Helper routines which wrap around Set/GetControlData.
  5.  
  6.     Version:    Appearance 1.0.2 SDK
  7.  
  8.     Copyright:    © 1997-98 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                Edward Voas
  13.  
  14.         Other Contact:        7 of 9, Borg Collective
  15.  
  16.         Technology:            OS Technologies Group
  17.  
  18.     Writers:
  19.  
  20.         (edv)    Ed Voas
  21.         (mxm)   Matt Mora
  22.         
  23.     Change History (most recent first):
  24.          <3>     1/23/98    mxm        Added #if !GENERATINGCFM for routines that are already in Appearance Library
  25.          <2>     9/11/97    edv        Fix header
  26.          <1>     9/11/97    edv        First checked in.
  27. */
  28.  
  29. #include <Appearance.h>
  30. #include <Resources.h>
  31. #include "AppearanceHelpers.h"
  32. #include "Assertions.h"
  33.  
  34. // Noone likes a mess. Here's some macros to help out.
  35.  
  36. #define ASSERT_ALIGNMENT( align )    \
  37.     ASSERT( ((align) == kControlBevelButtonAlignCenter) || ((align) == kControlBevelButtonAlignTop)    \
  38.             || ((align) == kControlBevelButtonAlignBottom) || ((align) == kControlBevelButtonAlignLeft)    \
  39.             || ((align) == kControlBevelButtonAlignRight) || ((align) == kControlBevelButtonAlignTopLeft) \
  40.             || ((align) == kControlBevelButtonAlignTopRight) || ((align) == kControlBevelButtonAlignBottomLeft) \
  41.             || ((align) == kControlBevelButtonAlignBottomRight) || ((align) == kControlBevelButtonAlignSysDirection) )
  42.  
  43. #define ASSERT_TEXT_ALIGNMENT( align )    \
  44.     ASSERT( ((align) == kControlBevelButtonAlignTextSysDirection) || ((align) == kControlBevelButtonAlignTextCenter)    \
  45.             || ((align) == kControlBevelButtonAlignTextFlushRight) || ((align) == kControlBevelButtonAlignTextFlushLeft) )
  46.  
  47. #define ASSERT_TEXT_PLACEMENT( align )    \
  48.     ASSERT( ((align) == kControlBevelButtonPlaceSysDirection) || ((align) == kControlBevelButtonPlaceToRightOfGraphic)    \
  49.             || ((align) == kControlBevelButtonPlaceToLeftOfGraphic) || ((align) == kControlBevelButtonPlaceBelowGraphic) \
  50.             || ((align) == kControlBevelButtonPlaceAboveGraphic) || ((align) == kControlBevelButtonPlaceNormally ) )
  51.  
  52.  
  53. #define MIN( a, b )        ( ( (a) < (b) ) ? (a) : (b) )
  54.  
  55. //—————————————————————————————————————————————————————————————————————————————
  56. //    • NewThemeMenu
  57. //—————————————————————————————————————————————————————————————————————————————
  58. //    Creates a theme-savvy menu on the fly. Since NewMenu assumes the usage of
  59. //    MDEF 0, we need to do a little fancy footwork to get around it. We get the
  60. //    theme MDEF and stuff the menuProc field of the menu with it.
  61. //
  62. pascal MenuHandle
  63. NewThemeMenu( SInt16 menuID, ConstStr255Param menuTitle )
  64. {
  65.     MenuHandle        menu;
  66.     
  67.     menu = NewMenu( menuID, menuTitle );
  68.     if ( menu )
  69.     {
  70.         Handle        themeDefProc = GetResource( 'MDEF', kMenuStdMenuProc );
  71.         
  72.         if ( themeDefProc )
  73.             (**menu).menuProc = themeDefProc;
  74.     }
  75.     return menu;
  76. }
  77.  
  78. //—————————————————————————————————————————————————————————————————————————————
  79. //    • GetEditTextText
  80. //—————————————————————————————————————————————————————————————————————————————
  81. //    Returns the text from an edit text control.
  82. //
  83. pascal OSStatus
  84. GetEditTextText( ControlHandle control, StringPtr text )
  85. {
  86.     Size        actualSize;
  87.     OSStatus    err;
  88.     
  89.     if ( control == nil )
  90.         return paramErr;
  91.         
  92.     if ( text == nil )
  93.         return paramErr;
  94.         
  95.     err = GetControlData( control, 0, kControlEditTextTextTag, 255, (Ptr)(text + 1), &actualSize );
  96.     if ( err == noErr )
  97.         text[0] = MIN( 255, actualSize );
  98.         
  99.     return err;
  100. }
  101.  
  102. //—————————————————————————————————————————————————————————————————————————————
  103. //    • SetEditTextText
  104. //—————————————————————————————————————————————————————————————————————————————
  105. //    Sets the text of an edit text control and optionally redraws it.
  106. //
  107. pascal OSStatus
  108. SetEditTextText( ControlHandle control, ConstStr255Param text, Boolean draw )
  109. {
  110.     OSStatus    err;
  111.     
  112.     if ( control == nil )
  113.         return paramErr;
  114.  
  115.     err = SetControlData( control, 0, kControlEditTextTextTag, text[0], (Ptr)(text+1) );
  116.     if ( (err == noErr) && draw )
  117.         DrawOneControl( control );
  118.     
  119.     return err;
  120. }
  121.  
  122. //—————————————————————————————————————————————————————————————————————————————
  123. //    • SetEditTextKeyFilter
  124. //—————————————————————————————————————————————————————————————————————————————
  125. //    Sets the text of an edit text control and optionally redraws it.
  126. //
  127. pascal OSStatus
  128. SetEditTextKeyFilter( ControlHandle control, ControlKeyFilterUPP filter )
  129. {
  130.     OSStatus    err;
  131.     
  132.     if ( control == nil )
  133.         return paramErr;
  134.         
  135.     if ( filter == nil )
  136.         return paramErr;
  137.  
  138.     err = SetControlData( control, 0, kControlKeyFilterTag, sizeof( filter ),
  139.             (Ptr)&filter );
  140.     
  141.     return err;
  142. }
  143.  
  144. //—————————————————————————————————————————————————————————————————————————————
  145. //    • SetEditTextSelection
  146. //—————————————————————————————————————————————————————————————————————————————
  147. //    Sets the selection of an edit text control and redraws it.
  148. //
  149. pascal OSStatus
  150. SetEditTextSelection( ControlHandle control, SInt16 selStart, SInt16 selEnd )
  151. {
  152.     ControlEditTextSelectionRec    selection;
  153.     OSStatus    err;
  154.  
  155.     if ( control == nil )
  156.         return paramErr;
  157.         
  158.     selection.selStart = selStart;
  159.     selection.selEnd = selEnd;
  160.     
  161.     err = SetControlData( control, 0, kControlEditTextSelectionTag,
  162.             sizeof( selection ), (Ptr)&selection );
  163.     
  164.     if ( err == noErr )
  165.         DrawOneControl( control );
  166.     
  167.     return err;
  168. }
  169.  
  170. //—————————————————————————————————————————————————————————————————————————————
  171. //    • GetEditTextSelection
  172. //—————————————————————————————————————————————————————————————————————————————
  173. //    Returns the selection for an edit text control.
  174. //
  175. pascal OSStatus
  176. GetEditTextSelection( ControlHandle control, SInt16* selStart, SInt16* selEnd )
  177. {
  178.     ControlEditTextSelectionRec    selection;
  179.     Size        actualSize;
  180.     OSStatus    err;
  181.     
  182.     if ( control == nil )
  183.         return paramErr;
  184.         
  185.     if ( selStart == nil )
  186.         return paramErr;
  187.         
  188.     if ( selEnd == nil )
  189.         return paramErr;
  190.         
  191.     err = GetControlData( control, 0, kControlEditTextSelectionTag,
  192.             sizeof( selection ), (Ptr)&selection, &actualSize );
  193.          
  194.     if ( err == noErr )
  195.     {
  196.         *selStart = selection.selStart;
  197.         *selEnd = selection.selEnd;
  198.     }
  199.         
  200.     return err;
  201. }
  202.  
  203. //—————————————————————————————————————————————————————————————————————————————
  204. //    • GetEditTextPasswordText
  205. //—————————————————————————————————————————————————————————————————————————————
  206. //    Returns the password text for an edit text password control.
  207. //
  208. pascal OSStatus
  209. GetEditTextPasswordText( ControlHandle control, StringPtr text )
  210. {
  211.     Size        actualSize;
  212.     OSStatus    err;
  213.     
  214.     if ( control == nil )
  215.         return paramErr;
  216.         
  217.     if ( text == nil )
  218.         return paramErr;
  219.  
  220.     err = GetControlData( control, 0, kControlEditTextPasswordTag,
  221.             255, (Ptr)(text+1), &actualSize );
  222.          
  223.     if ( err == noErr )
  224.         text[0] = MIN( 255, actualSize );
  225.         
  226.     return err;
  227. }
  228.  
  229. //—————————————————————————————————————————————————————————————————————————————
  230. //    • GetStaticTextText
  231. //—————————————————————————————————————————————————————————————————————————————
  232. //    Returns the text from an edit text control.
  233. //
  234. pascal OSStatus
  235. GetStaticTextText( ControlHandle control, StringPtr text )
  236. {
  237.     Size        actualSize;
  238.     OSStatus    err;
  239.     
  240.     if ( control == nil )
  241.         return paramErr;
  242.         
  243.     if ( text == nil )
  244.         return paramErr;
  245.         
  246.     err = GetControlData( control, 0, kControlStaticTextTextTag, 255, (Ptr)(text + 1), &actualSize );
  247.     if ( err == noErr )
  248.         text[0] = MIN( 255, actualSize );
  249.         
  250.     return err;
  251. }
  252.  
  253. //—————————————————————————————————————————————————————————————————————————————
  254. //    • SetStaticTextText
  255. //—————————————————————————————————————————————————————————————————————————————
  256. //    Sets the text of an edit text control and optionally redraws it.
  257. //
  258. pascal OSStatus
  259. SetStaticTextText( ControlHandle control, ConstStr255Param text, Boolean draw )
  260. {
  261.     OSStatus    err;
  262.     
  263.     if ( control == nil )
  264.         return paramErr;
  265.  
  266.     err = SetControlData( control, 0, kControlStaticTextTextTag, text[0], (Ptr)(text+1) );
  267.     if ( (err == noErr) && draw )
  268.         DrawOneControl( control );
  269.     
  270.     return err;
  271. }
  272.  
  273. //—————————————————————————————————————————————————————————————————————————————
  274. //    • GetStaticTextTextHeight
  275. //—————————————————————————————————————————————————————————————————————————————
  276. //    Returns the actual height of the text, not the control height.
  277. //
  278. pascal OSStatus
  279. GetStaticTextTextHeight( ControlHandle control, SInt16* height )
  280. {
  281.     Size        actualSize;
  282.     OSStatus    err;
  283.     
  284.     if ( control == nil )
  285.         return paramErr;
  286.         
  287.     if ( height == nil )
  288.         return paramErr;
  289.         
  290.     err = GetControlData( control, 0, kControlStaticTextTextHeightTag, sizeof( SInt16 ),
  291.          (Ptr)height, &actualSize );
  292.         
  293.     return err;
  294. }
  295.  
  296. //—————————————————————————————————————————————————————————————————————————————
  297. //    • SetProgressIndicatorState
  298. //—————————————————————————————————————————————————————————————————————————————
  299. //    Sets a progress bar to the determinate or indeterminate state.
  300. //
  301. pascal OSStatus
  302. SetProgressIndicatorState( ControlHandle control, Boolean isDeterminate )
  303. {
  304.     OSStatus    err;
  305.     Boolean        state;
  306.     
  307.     if ( control == nil )
  308.         return paramErr;
  309.  
  310.     state = !isDeterminate;    
  311.     err = SetControlData( control, 0, kControlProgressBarIndeterminateTag, sizeof( state ),
  312.             (Ptr)&state );
  313.     
  314.     return err;
  315. }
  316.  
  317. //—————————————————————————————————————————————————————————————————————————————
  318. //    • GetProgressIndicatorState
  319. //—————————————————————————————————————————————————————————————————————————————
  320. //    Returns the state of the button's default status.
  321. //
  322. pascal OSStatus
  323. GetProgressIndicatorState( ControlHandle control, Boolean* isDeterminate )
  324. {
  325.     Size        actualSize;
  326.     OSStatus    err;
  327.     Boolean        temp;
  328.     
  329.     if ( control == nil )
  330.         return paramErr;
  331.         
  332.     if ( isDeterminate == nil )
  333.         return paramErr;
  334.         
  335.     err = GetControlData( control, 0, kControlListBoxListHandleTag, sizeof( temp ),
  336.              (Ptr)&temp, &actualSize );
  337.     
  338.     if ( err == noErr )
  339.         *isDeterminate = !temp;
  340.         
  341.     return err;
  342. }
  343.  
  344. //—————————————————————————————————————————————————————————————————————————————
  345. //    • SetPushButtonDefaultState
  346. //—————————————————————————————————————————————————————————————————————————————
  347. //    Sets a push button's default flag. This lets the button know whether or not
  348. //    to draw its default ring.
  349. //
  350. pascal OSStatus
  351. SetPushButtonDefaultState( ControlHandle control, Boolean isDefault )
  352. {
  353.     OSStatus    err;
  354.     
  355.     if ( control == nil )
  356.         return paramErr;
  357.  
  358.     err = SetControlData( control, 0, kControlPushButtonDefaultTag, sizeof( isDefault ),
  359.             (Ptr)&isDefault );
  360.     
  361.     return err;
  362. }
  363.  
  364. //—————————————————————————————————————————————————————————————————————————————
  365. //    • GetPushButtonDefaultState
  366. //—————————————————————————————————————————————————————————————————————————————
  367. //    Returns the state of the button's default status.
  368. //
  369. pascal OSStatus
  370. GetPushButtonDefaultState( ControlHandle control, Boolean* isDefault )
  371. {
  372.     Size        actualSize;
  373.     OSStatus    err;
  374.     
  375.     if ( control == nil )
  376.         return paramErr;
  377.         
  378.     if ( isDefault == nil )
  379.         return paramErr;
  380.         
  381.     err = GetControlData( control, 0, kControlListBoxListHandleTag, sizeof( Boolean ),
  382.              (Ptr)isDefault, &actualSize );
  383.         
  384.     return err;
  385. }
  386.  
  387. //—————————————————————————————————————————————————————————————————————————————
  388. //    • GetListBoxListHandle
  389. //—————————————————————————————————————————————————————————————————————————————
  390. //    Returns the list handle from a list box control.
  391. //
  392. pascal OSStatus
  393. GetListBoxListHandle( ControlHandle control, ListHandle* list )
  394. {
  395.     Size        actualSize;
  396.     OSStatus    err;
  397.     
  398.     if ( control == nil )
  399.         return paramErr;
  400.         
  401.     if ( list == nil )
  402.         return paramErr;
  403.         
  404.     err = GetControlData( control, 0, kControlListBoxListHandleTag, sizeof( ListHandle ),
  405.              (Ptr)list, &actualSize );
  406.         
  407.     return err;
  408. }
  409.  
  410. //—————————————————————————————————————————————————————————————————————————————
  411. //    • SetListBoxKeyFilter
  412. //—————————————————————————————————————————————————————————————————————————————
  413. //    Sets the key filter for a list box control.
  414. //
  415. pascal OSStatus
  416. SetListBoxKeyFilter( ControlHandle control, ControlKeyFilterUPP filter )
  417. {
  418.     OSStatus    err;
  419.     
  420.     if ( control == nil )
  421.         return paramErr;
  422.     
  423.     if ( filter == nil )
  424.         return paramErr;
  425.  
  426.     err = SetControlData( control, 0, kControlKeyFilterTag, sizeof( filter ),
  427.             (Ptr)&filter );
  428.     
  429.     return err;
  430. }
  431.  
  432. //—————————————————————————————————————————————————————————————————————————————
  433. //    • SetIconControlTransform
  434. //—————————————————————————————————————————————————————————————————————————————
  435. //    Sets the transform for an icon control.
  436. //
  437. pascal OSStatus
  438. SetIconControlTransform( ControlHandle control, IconTransformType transform )
  439. {
  440.     OSStatus    err;
  441.     
  442.     if ( control == nil )
  443.         return paramErr;
  444.     
  445.     err = SetControlData( control, 0, kControlIconTransformTag, sizeof( transform ),
  446.             (Ptr)&transform );
  447.     
  448.     return err;
  449. }
  450.  
  451. //—————————————————————————————————————————————————————————————————————————————
  452. //    • SetIconControlAlignment
  453. //—————————————————————————————————————————————————————————————————————————————
  454. //    Sets the alignment for an icon control.
  455. //
  456. pascal OSStatus
  457. SetIconControlAlignment( ControlHandle control, IconAlignmentType align )
  458. {
  459.     OSStatus    err;
  460.     
  461.     if ( control == nil )
  462.         return paramErr;
  463.     
  464.     err = SetControlData( control, 0, kControlIconAlignmentTag, sizeof( align ),
  465.             (Ptr)&align );
  466.     
  467.     return err;
  468. }
  469.  
  470. //—————————————————————————————————————————————————————————————————————————————
  471. //    • SetClockDateTime
  472. //—————————————————————————————————————————————————————————————————————————————
  473. //    Sets the time for a clock control.
  474. //
  475. pascal OSStatus
  476. SetClockDateTime( ControlHandle control, const LongDateRec* time )
  477. {
  478.     OSStatus    err;
  479.     
  480.     if ( control == nil )
  481.         return paramErr;
  482.     
  483.     err = SetControlData( control, 0, kControlClockLongDateTag,
  484.             sizeof( LongDateRec ), (Ptr)time );
  485.     
  486.     return err;
  487. }
  488.  
  489. //—————————————————————————————————————————————————————————————————————————————
  490. //    • GetClockDateTime
  491. //—————————————————————————————————————————————————————————————————————————————
  492. //    Returns the time from a clock control.
  493. //
  494. pascal OSStatus
  495. GetClockDateTime( ControlHandle control, LongDateRec* time )
  496. {
  497.     Size        actualSize;
  498.     OSStatus    err;
  499.     
  500.     if ( control == nil )
  501.         return paramErr;
  502.         
  503.     if ( time == nil )
  504.         return paramErr;
  505.         
  506.     err = GetControlData( control, 0, kControlClockLongDateTag,
  507.             sizeof( LongDateRec ), (Ptr)time, &actualSize );
  508.         
  509.     return err;
  510. }
  511.  
  512.  
  513. // <3>
  514. // The rest of these routines are already in the Appearance Library
  515. // so we don't include these routines if we are compiling for CFM
  516.  
  517. #if !GENERATINGCFM
  518. //——————————————————————————————————————————————————————————————————————————————————————————————————————
  519. //
  520. // • BEVEL BUTTON ROUTINES
  521. //
  522. //——————————————————————————————————————————————————————————————————————————————————————————————————————
  523.  
  524.  
  525.  
  526. //=========================================================================================
  527. //    • GetBevelButtonMenuValue                                                        PUBLIC
  528. //=========================================================================================
  529. //    Returns the current menuValue of the bevel button, if any. If the bevel button supports
  530. //    multivalued menus, it will return the last one chosen.
  531. //
  532. pascal OSErr
  533. GetBevelButtonMenuValue( ControlRef button, SInt16* value )
  534. {
  535.     OSErr        err;
  536.     
  537.     ASSERT_GOTO( button != nil, noButton );
  538.  
  539.     err = GetControlData( button, 0, kControlBevelButtonMenuValueTag, sizeof( SInt16 ),
  540.                         (Ptr)value, nil );
  541.     
  542.     return err;
  543.  
  544. noButton:
  545.     return paramErr;
  546. }
  547.  
  548. //=========================================================================================
  549. //    • SetBevelButtonMenuValue                                                        PUBLIC
  550. //=========================================================================================
  551. //    Sets the current value of the menu.
  552. //
  553. pascal OSErr
  554. SetBevelButtonMenuValue( ControlRef button, SInt16 value )
  555. {
  556.     OSErr        err;
  557.     
  558.     ASSERT_GOTO( button != nil, noButton );
  559.  
  560.     err = SetControlData( button, 0, kControlBevelButtonMenuValueTag, sizeof( SInt16 ),
  561.                         (Ptr)&value );
  562.     
  563.     return err;
  564.  
  565. noButton:
  566.     return paramErr;
  567. }
  568.  
  569.  
  570. //=========================================================================================
  571. //    • GetBevelButtonMenuHandle                                                        PUBLIC
  572. //=========================================================================================
  573. //    Returns the current menuHandle of the bevel button, if any.
  574. //
  575. pascal OSErr
  576. GetBevelButtonMenuHandle( ControlRef button, MenuHandle* handle )
  577. {
  578.     OSErr        err;
  579.     
  580.     ASSERT_GOTO( button != nil, noButton );
  581.  
  582.     err = GetControlData( button, 0, kControlBevelButtonMenuHandleTag, sizeof( MenuHandle ),
  583.                         (Ptr)handle, nil );
  584.     
  585.     return err;
  586.  
  587. noButton:
  588.     return paramErr;
  589. }
  590.  
  591. //=========================================================================================
  592. //    • GetBevelButtonContentInfo                                                    PUBLIC
  593. //=========================================================================================
  594. //    Returns the current type of data we are displaying and the handle to that data.
  595. //
  596. pascal OSErr
  597. GetBevelButtonContentInfo( ControlRef button, const ControlButtonContentInfoPtr info )
  598. {
  599.     OSErr        err;
  600.     
  601.     ASSERT_GOTO( button != nil, noButton );
  602.  
  603.     err = GetControlData( button, 0, kControlBevelButtonContentTag, sizeof( ControlButtonContentInfo ),
  604.                         (Ptr)info, nil );
  605.     
  606.     return err;
  607.  
  608. noButton:
  609.     return paramErr;
  610. }
  611.  
  612. //=========================================================================================
  613. //    • SetBevelButtonContentInfo                                                    PUBLIC
  614. //=========================================================================================
  615. //    Sets the current content type and data for the button's content. If the current content
  616. //    was created by the button (i.e. resource based) it is disposed.
  617. //
  618. pascal OSErr
  619. SetBevelButtonContentInfo( ControlRef button, ControlButtonContentInfoPtr info )
  620. {
  621.     OSErr        err;
  622.     
  623.     ASSERT_GOTO( button != nil, noButton );
  624.  
  625.     err = SetControlData( button, 0, kControlBevelButtonContentTag, sizeof( ControlButtonContentInfo ),
  626.                 (Ptr)info );
  627.  
  628.     return err;
  629.     
  630. noButton:
  631.     return paramErr;
  632. }
  633.  
  634. //=========================================================================================
  635. //    • SetBevelButtonTransform                                                        PUBLIC
  636. //=========================================================================================
  637. //    Sets the transform that will be OR'ed into the calculated transform for the icon. This
  638. //    can be used to add a label color or an offline attribute, etc.
  639. //
  640. pascal OSErr
  641. SetBevelButtonTransform( ControlRef button, IconTransformType transform )
  642. {
  643.     OSErr        err;
  644.     
  645.     ASSERT_GOTO( button != nil, noButton );
  646.  
  647.     err = SetControlData( button, 0, kControlBevelButtonTransformTag, sizeof( transform ), (Ptr)&transform );
  648.  
  649.     return err;
  650.     
  651. noButton:
  652.     return paramErr;
  653. }
  654.  
  655. //=========================================================================================
  656. //    • SetBevelButtonTextOptions                                                        PUBLIC
  657. //=========================================================================================
  658. //    Sets the current text options.
  659. //
  660. pascal OSErr
  661. SetBevelButtonTextAlignment( ControlRef button, ControlButtonTextAlignment align, SInt16 hOffset )
  662. {
  663.     OSErr        err;
  664.     
  665.     ASSERT_GOTO( button != nil, noButton );
  666.  
  667.     err = SetControlData( button, 0, kControlBevelButtonTextAlignTag, sizeof( ControlButtonTextAlignment ),
  668.                         (Ptr)&align );
  669.  
  670.     if ( err == noErr )
  671.     {
  672.         err = SetControlData( button, 0, kControlBevelButtonTextOffsetTag, sizeof( SInt16 ),
  673.                         (Ptr)&hOffset );
  674.     }
  675.     return err;
  676.     
  677. noButton:
  678.     return paramErr;
  679. }
  680.  
  681.  
  682. //=========================================================================================
  683. //    • SetBevelButtonGraphicAlignment                                                PUBLIC
  684. //=========================================================================================
  685. //    Sets the aligment options for the button graphic.
  686. //
  687. pascal OSErr
  688. SetBevelButtonGraphicAlignment( ControlRef button, ControlButtonGraphicAlignment align, SInt16 hOffset, SInt16 vOffset )
  689. {
  690.     OSErr        err;
  691.     Point        offset;
  692.     
  693.     ASSERT_GOTO( button != nil, noButton );
  694.  
  695.     ASSERT_ALIGNMENT( align );
  696.  
  697.     
  698.     ASSERT( hOffset >= 0 );
  699.     ASSERT( vOffset >= 0 );
  700.     
  701.     err = SetControlData( button, 0, kControlBevelButtonGraphicAlignTag, sizeof( ControlButtonGraphicAlignment ),
  702.                         (Ptr)&align );
  703.  
  704.     if ( err == noErr )
  705.     {
  706.         offset.h = hOffset;
  707.         offset.v = vOffset;
  708.         
  709.         err = SetControlData( button, 0, kControlBevelButtonGraphicOffsetTag, sizeof( Point ),
  710.                         (Ptr)&offset );
  711.     }
  712.  
  713.     return err;
  714.     
  715. noButton:
  716.     return paramErr;
  717. }
  718.  
  719. //=========================================================================================
  720. //    • SetBevelButtonTextPlacement                                                    PUBLIC
  721. //=========================================================================================
  722. //    Sets the text placement for buttons with a combination of text and a graphic. This
  723. //    routine also sets the alignment to the proper alignment based on the current graphic
  724. //    alignment.
  725. //
  726. pascal OSErr
  727. SetBevelButtonTextPlacement( ControlRef button, ControlButtonTextPlacement where )
  728. {
  729.     OSErr        err;
  730.     
  731.     ASSERT_GOTO( button != nil, noButton );
  732.  
  733.     err = SetControlData( button, 0, kControlBevelButtonTextPlaceTag, sizeof( ControlButtonTextPlacement ),
  734.                 (Ptr)&where );
  735.  
  736.     return err;
  737.     
  738. noButton:
  739.     return paramErr;
  740. }
  741.  
  742. //=========================================================================================
  743. //    • GetImageWellContentInfo                                                        PUBLIC
  744. //=========================================================================================
  745. //    Returns the current type of data we are displaying and the handle to that data.
  746. //
  747. pascal OSErr
  748. GetImageWellContentInfo( ControlRef button, const ControlButtonContentInfoPtr info )
  749. {
  750.     OSErr        err;
  751.     
  752.     ASSERT_GOTO( button != nil, noButton );
  753.  
  754.     err = GetControlData( button, 0, kControlImageWellContentTag, sizeof( ControlButtonContentInfo ),
  755.                         (Ptr)info, nil );
  756.     
  757.     return err;
  758.  
  759. noButton:
  760.     return paramErr;
  761. }
  762.  
  763.  
  764. //=========================================================================================
  765. //    • SetImageWellContentInfo                                                        PUBLIC
  766. //=========================================================================================
  767. //    Sets the current content type and data for the button's content. If the current content
  768. //    was created by the button (i.e. resource based) it is disposed.
  769. //
  770. pascal OSErr
  771. SetImageWellContentInfo( ControlRef button, ControlButtonContentInfoPtr info )
  772. {
  773.     OSErr        err;
  774.     
  775.     ASSERT_GOTO( button != nil, noButton );
  776.  
  777.     err = SetControlData( button, 0, kControlImageWellContentTag, sizeof( ControlButtonContentInfo ), (Ptr)info );
  778.  
  779.     return err;
  780.     
  781. noButton:
  782.     return paramErr;
  783. }
  784.  
  785.  
  786. //=========================================================================================
  787. //    • SetImageWellTransform                                                            PUBLIC
  788. //=========================================================================================
  789. //    Sets the transform that will be OR'ed into the calculated transform for the icon. This
  790. //    can be used to add a label color or an offline attribute, etc.
  791. //
  792. pascal OSErr
  793. SetImageWellTransform( ControlRef button, IconTransformType transform )
  794. {
  795.     OSErr        err;
  796.     
  797.     ASSERT_GOTO( button != nil, noButton );
  798.  
  799.     err = SetControlData( button, 0, kControlImageWellTransformTag, sizeof( transform ), (Ptr)&transform );
  800.  
  801.     return err;
  802.     
  803. noButton:
  804.     return paramErr;
  805. }
  806.  
  807. //=========================================================================================
  808. //    • GetTabContentRect                                                                PUBLIC
  809. //=========================================================================================
  810. //    Gets the content area of a tab control.
  811. //
  812. pascal OSErr
  813. GetTabContentRect( ControlRef tabControl, Rect* contentRect )
  814. {
  815.     OSErr        err;
  816.     
  817.     ASSERT_GOTO( tabControl != nil, noButton );
  818.  
  819.     err = GetControlData( tabControl, 0, kControlTabContentRectTag, sizeof( Rect ),
  820.                         (Ptr)contentRect, nil );
  821.     
  822.     return err;
  823.  
  824. noButton:
  825.     return paramErr;
  826. }
  827.  
  828. //=========================================================================================
  829. //    • SetTabEnabled                                                                    PUBLIC
  830. //=========================================================================================
  831. //    Sets the hilite flag of a particular tab of a tab control.
  832. //
  833. pascal OSErr
  834. SetTabEnabled( ControlRef tabControl, SInt16 tabToHilite, Boolean enabled )
  835. {
  836.     OSErr        err;
  837.     
  838.     ASSERT_GOTO( tabControl != nil, noButton );
  839.  
  840.     err = SetControlData( tabControl, tabToHilite, kControlTabEnabledFlagTag, sizeof( Boolean ),
  841.                         (Ptr)&enabled );
  842.     
  843.     return err;
  844.  
  845. noButton:
  846.     return paramErr;
  847. }
  848.  
  849.  
  850.  
  851. //=========================================================================================
  852. //    • SetDisclosureTriangleLastValue                                                PUBLIC
  853. //=========================================================================================
  854. //    Sets the 'last value' field of a disclosure triangle. This is useful.
  855. //
  856. pascal OSErr
  857. SetDisclosureTriangleLastValue( ControlRef triangle, SInt16 value )
  858. {
  859.     OSErr        err;
  860.     
  861.     ASSERT_GOTO( triangle != nil, noButton );
  862.  
  863.     err = SetControlData( triangle, 0, kControlTriangleLastValueTag, sizeof( SInt16 ), (Ptr)&value );
  864.     
  865.     return err;
  866.  
  867. noButton:
  868.     return paramErr;
  869. }
  870.  
  871. #endif //#if !GENERATINGCFM
  872.  
  873.